<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>addClass</title>
</head>

<body>
    <div id="test" class="test">当前类名为test</div>
    <button type="button" class="btn" id="testBtn">点击我</button>
    <script>
        const testBtn = document.getElementById('testBtn');
        const test = document.getElementById('test');
        const addClass = (el, className) => el.classList.add(className);
        testBtn.onclick = () => {
            addClass(test, 'test1');
            test.textContent = `当前类名为:${test.className}`;
        }
    </script>
</body>

</html>